<layout name='Layout/layout_main' />
<script type="text/javascript">
		function add() {
			window.open("{:U('add')}", "_self");
		}
		function del(obj){
			if(confirm('确定要删除吗?')){
				id=$(obj).parent().parent().find("input.node").val();
				sendAjax("{:U('del')}","id="+id,function(data){
					$(obj).parent().parent().remove();
					alert(data.info);
				});	
			}
		}
		$(document).ready(function(){
			set_return_url();
			$("#dialog2").mouseleave(function() {
				$("#dialog2").hide();
			});

			$("li a.status").live("click",(function(){
				$("#dialog2").css("left", $(this).parents("span").offset().left);
				$("#dialog2").css("top", $(this).parents("span").offset().top);
				$("#dialog2").show();
				node=$(this).parents("li").find("input.node").val();
				$("#dialog2").attr("node",node);
			}))

			$("li").each(function(){
				$(this).css("background-color",schedule_bg($(this).find("input.priority").val()));	
			})
			$("a.up").click(function(){
				moveUp($(this));
			})
			$("a.down").click(function(){
				moveDown($(this));
			})
		})

		function moveUp(obj){
			var current=$(obj).parent().parent();  
			var prev=current.prev();			
			if(current.index()>1){
				current.insertBefore(prev);
				current.find("input.priority").val(prev.find("input.priority").val());
				current.css("background-color",schedule_bg(current.find("input.priority").val()));
			}
			set_sort();
		}

		function moveDown(obj){
			var current=$(obj).parent().parent();  
			var next=current.next();
			if(next){
				current.insertAfter(next);
				current.find("input.priority").val(next.find("input.priority").val());
				current.css("background-color",schedule_bg(next.find("input.priority").val()));
			}
			set_sort();
		}

		function mark_status(val){
			node=$("#dialog2").attr("node");
			if (node)
			{
				sendAjax("{:U('mark_status')}","id="+node+"&val="+val,function(data){
					alert(data.info);
					location.href=location.href;
				});
			}
		}

		function set_sort(){
			$("li.tbody").each(function(){
				$(this).find("input.sort").val($(this).index());
			})
			var vars = $("#form_data").serialize();
			sendAjax("{:U('ajaxRead')}", vars);
		}
		
</script>
<div class="todo">
	<form method="post" action="" id="form_search" name="form_search">
		<div class="row-fluid title">
			<span>待办事项</span>
			<div class="input-append right">
				<input type="text"  onkeydown="key_search();" name="keyword" id="keyword">
				<a class="btn" onclick="btn_search();"> <i class="icon-search"></i>
				</a>
			</div>
		</div>
	</form>
	<form id="form_data" name="form_data" method='post'>
		<div class="row-fluid operate">
			<div class="left"></div>
			<div class="right">
				<a  onclick="add();" class="btn" >新建</a>
			</div>
		</div>
		<div>
			<div class="table span-12 last">
				<ul>
					<li class="thead">
						<span class="col-3 right">&nbsp;</span>
						<span class="col-3 right">&nbsp;</span>
						<span class="col-3 right">&nbsp;</span>
						<span class="col-6 right">状态</span>
						<span class="col-9 right">截至日期</span>
						<div class="auto autocut text-left">待办事项</div>
					</li>
					<foreach name="list" item="vo" >
						<li class="tbody" node="{$vo.id}">
							<input class="node" type="hidden" name="node[]" value="{$vo.id}">
							<input class="priority" type="hidden" name="priority[]" value="{$vo.priority}">
							<input class="sort" type="hidden" name="sort[]">
							<span class="col-3 right text-center">
								<a title="删除" class="del" onclick="del(this);">✕</a>
							</span>
							<span class="col-3 right text-center">
								<a title="低" class="down">&#9660;</a>
							</span>
							<span class="col-3 right text-center">
								<a title="高" class="up">&#9650;</a>
							</span>
							<span class="col-6 right text-center">
								<a class="status">{$vo.status|todo_status}</a>
							</span>
							<span class="col-9 right text-center">{$vo.end_date}</span>
							<span class="auto">
								<a href="{:U('edit?id='.$vo['id'])}">{$vo.name}</a>
							</span>
						</li>
					</foreach>
				</ul>
				<br>
				<ul>
					<li class="thead">
						<span class="col-3 right">&nbsp;</span>
						<span class="col-3 right">&nbsp;</span>
						<span class="col-3 right">&nbsp;</span>
						<span class="col-6 right">状态</span>
						<span class="col-9 right">完成日期</span>
						<div class="auto autocut text-left">已完成事项</div>
					</li>
					<foreach name="list2" item="vo">
						<li class="tbody" node="{$vo.id}">
							<input class="node" type="hidden" name="node[]" value="{$vo.id}">
							<input class="priority" type="hidden" name="priority[]" value="{$vo.priority}">
							<input class="sort" type="hidden" name="sort[]">
							<span class="col-3 right text-center">
								<a title="删除" class="del" onclick="del(this);">✕</a>
							</span>
							<span class="col-3 right text-center">
								<a title="低" class="down">&#9660;</a>
							</span>
							<span class="col-3 right text-center">
								<a title="高" class="up">&#9650;</a>
							</span>
							<span class="col-6 right text-center">
								<a class="status">{$vo.status|todo_status}</a>
							</span>
							<span class="col-9 right text-center">{$vo.end_date}</span>
							<span class="auto">
								<a href="{:U('edit?id='.$vo['id'])}">{$vo.name}</a>
							</span>
						</li>
					</foreach>
				</ul>
			</div>
		</div>
	</form>
	<div id="dialog2" class="dropdown">
		<ul class="dropdown-menu">
			<li>
				<a onclick="mark_status(1);">尚未开始</a>
			</li>
			<li>
				<a onclick="mark_status(2);">正在进行</a>
			</li>
			<li>
				<a onclick="mark_status(3);">完成</a>
			</li>
		</ul>
	</div>
</div>